<template>
	<view class="course-list">
		<view v-if="courseList.length > 0">
			<view v-for="course in courseList" :key="course.id"
				@click="goStudy(course.id,course.courseName,course.currentSessionNumber )" class="course-item">
				<image class="course-image" src="/static/img/logo1.png"></image>
				<view class="course-info">
					<text class="course-name">{{ course.courseName }}</text>
					<text class="course-session">第{{ course.currentSessionNumber }}期</text>
				</view>
			</view>
		</view>
		<view v-else class="no-course-card">
			<text>您还没有报名课程，快去首页报名吧</text>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				courseList: []
			};
		},
		created() {
			this.getMyCourse();
		},
		methods: {
			getMyCourse() {
				let userinfo = uni.getStorageSync('userInfo')

				uni.request({
					url: 'http://localhost:9090/course/getMyCourse',
					method: 'POST',
					data: {
						id: userinfo.id
					},
					success: (res) => {
						if (res.data.data && res.data.data.length > 0) {
							this.courseList = res.data.data;
						}
					},
					fail: (err) => {
						console.error('获取课程列表失败:', err);
					}
				});
			},
			goStudy(courseId, courseName,currentSessionNumber) {
				uni.navigateTo({
					url: '/pages/study/index?courseId=' + courseId + '&courseName=' + courseName + '&currentSessionNumber=' +
						currentSessionNumber
				});
			}
		}
	};
</script>

<style scoped>
	.course-list {
		padding: 10px;
	}

	.course-item {
		display: flex;
		align-items: center;
		margin-bottom: 10px;
		border: 1px solid #ccc;
		padding: 10px;
		border-radius: 5px;
	}

	.course-image {
		width: 80px;
		height: 80px;
		margin-right: 10px;
	}

	.course-info {
		display: flex;
		flex-direction: column;
	}

	.course-name {
		font-size: 16px;
		font-weight: bold;
	}

	.course-session {
		font-size: 14px;
		color: #666;
	}

	.no-course-card {
		border: 1px solid #ccc;
		padding: 10px;
		border-radius: 5px;
		text-align: center;
		color: #666;
	}
</style>